#include <iostream>
using namespace std;
int main() {
	int arr[12] = { 1,-2,4,5,-2,8,3,-2,6,3,7,-1 };
	int n = sizeof(arr) / sizeof(arr[0]);
	int* D = new int[n];
	int* Rec = new int[n];
	D[n - 1] = arr[n - 1];
	Rec[n - 1] = n - 1;
	for (int i = n - 2; i >= 0; i--) {
		if (D[i + 1] >= 0) {
			D[i] = D[i + 1] + arr[i];
			Rec[i] = Rec[i + 1];
		}
		else {
			D[i] = arr[i];
			Rec[i] = i;
		}
	}
	int Max = D[0];
	int j = 0;
	int num = Rec[0];
	for (int i = 0; i < n; i++) {
		if (D[i] > Max) {
			Max = D[i];
			j = i;
			num = Rec[i];
		}
	}
	for (int i = j; i <= num; i++) {
		cout << arr[i] << " ";
	}
	return 0;
}